package com.qf.sy2103.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.sy2103.ssm.dao.GongnengDao;
import com.qf.sy2103.ssm.entity.Gongneng;
import com.qf.sy2103.ssm.entity.Kehu;
import com.qf.sy2103.ssm.service.GongnengService;
import com.qf.sy2103.ssm.vo.PageVo;
import com.qf.sy2103.ssm.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class GongnengServiceImpl implements GongnengService {
    @Autowired
    private GongnengDao gongnengDao;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int add(Gongneng gongneng) {
        return gongnengDao.insert(gongneng);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updata(Gongneng gongneng) {
        return gongnengDao.update(gongneng);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int del(Integer[] id) {
        return gongnengDao.delete(id);
    }
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public TableVo<Gongneng> all(PageVo pageVo, Gongneng gongneng) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<Gongneng> gongnengs = gongnengDao.selectall(gongneng);
        PageInfo<Gongneng> pageInfo=new PageInfo<>(gongnengs);
        return new TableVo<Gongneng>(0,"ok",pageInfo.getTotal(),gongnengs);
    }
}
